package com.qut.system_1.util;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Date;

@Component
public class EmailUtil {
    @Resource
    private JavaMailSender javaMailSender;

    public int sendMail(String mail){
        int row=0;
        MimeMessage msg=javaMailSender.createMimeMessage();
        try {
            MimeMessageHelper helper=new MimeMessageHelper(msg,true);
            helper.setText("<a href='http://localhost:8088/demo/searchPwd.html'>找回密码</a>",true);
            helper.addTo("3505561132@qq.com");
            helper.setFrom("3505561132@qq.com");
            helper.setSubject("测试");
            helper.setSentDate(new Date());
            javaMailSender.send(msg);
            row=1;
        } catch (MessagingException e) {
            e.printStackTrace();
        }
        return row;
    }
}
